<%@ page import="java.sql.Statement" import="java.sql.ResultSet" import="java.sql.Connection" %>
<%@page import="connection.DBConnection"%>
<%@page import="java.util.*" %>
<%@page import="java.text.SimpleDateFormat" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form>
<table border=2 align="center">
<%  DBConnection dbc=new DBConnection();
			Connection con=dbc.getNewConnection();
			String selectedinv = (String) request.getAttribute("cin");
			String selectedname = (String) request.getAttribute("cname");
			String selectedcode = (String) request.getAttribute("ccd");
			String group = (String) request.getAttribute("grp");
			
			Statement st = null;
			ResultSet rs = null;
			 String inv="",newdate="",cd1="";
			 double adj=0.0,amt1=0.0,tot1=0.0;
			 int cred=0,cred1=0;
			 %>
			 <tr><th colspan=4 align=center><%=selectedname %></th></tr>
<tr>
		<td>Date </td>
		<td>Due date</td>
    	<td>Reference number</td>
    	<td>Amount </td>
    	</tr>
<%


SimpleDateFormat sim = new SimpleDateFormat("dd-MM-yyyy");

Calendar calendar = Calendar.getInstance();
SimpleDateFormat fromsql = new SimpleDateFormat("yyyy-MM-dd");
try{
	 st=con.createStatement() ;
rs=st.executeQuery("select date, scode,pvinno, sum(pvtota),pvcredlim from purchasevoucher2 where pvsname='"+selectedname+"' and scode='"+selectedcode+"' group by pvinno");
while(rs.next())
{ 
String dt=rs.getString(1);
cd1=rs.getString(2);
String inn1=rs.getString(3);

double tot=rs.getDouble(4);
cred1=rs.getInt(5);
 tot1=tot1+tot;

String newdate1 =sim.format(fromsql.parse(dt));

calendar.setTime(sim.parse(newdate1));
calendar.add(Calendar.DATE,cred1); 
String due1 = sim.format(calendar.getTime());
%>
<tr>
	         <td><%=newdate1%></td>
	         <td><%=due1 %></td>
	       <td><%=inn1 %></td>
	         <td><%=tot%></td>
	         </tr>
	         
	         <%
	 		}
con.close();
}
			catch(Exception e){} %>
			<tr><td></td><td></td><td>Total</td><td><%=tot1 %></td></tr>
</table>
<br>
<center><input type="button" value="Print this page" onClick="window.print()"></center>

</form>
</body>
</html>